cap log close

global path = "****"

local name= "cov_fpl_expansion"
local date = "052720"
global logname = "$path/`name'_`date'.log"

clear
set more off
set matsize 11000
cd "$path"
log using "$logname", replace

use "$path/Data/penalty_sample.dta", clear

replace age_2017=0 if age_2017<0

replace age_2017=0 if age_2017<0
rename fpl_frac magi_fpl2015

gen age_45_64 = age_2017 < 65 & age_2017 >= 45

foreach var in exchange medicaid esi off_exchange va medicare{
gen `var'1718 = `var'2017 + `var'2018
}

gen non_medicaid1718 = exchange1718 + esi1718 + off_exchange1718 + va1718 + medicare1718

*Table: Effect by Income and Expansion State (Intensive Margin)

estimates clear 
eststo clear

foreach cov in medicaid non_medicaid{
*Panel A: All Ages 

*Column 1: FPL <= 1.38
reg `cov'1718 treatment if notall16 == 1 & magi_fpl2015<=1.38, cl(tin)
eststo
estadd scalar nobs e(N)
summ `e(depvar)' if e(sample)&treatment==0
estadd scalar ymean=r(mean)
estimates save "$path/`cov'_fpl_exp_`date'.ster", replace

*Column 2: FPL > 1.38
reg `cov'1718 treatment if notall16 == 1 & magi_fpl2015>1.38, cl(tin)
eststo
estadd scalar nobs e(N)
summ `e(depvar)' if e(sample)&treatment==0
estadd scalar ymean=r(mean)
estimates save "$path/`cov'_fpl_exp_`date'.ster", append

*Column 3: FPL <= 1.38 & Expansion State
reg `cov'1718 treatment if notall16 == 1 & magi_fpl2015<=1.38 & expansion == 1, cl(tin)
eststo
estadd scalar nobs e(N)
summ `e(depvar)' if e(sample)&treatment==0
estadd scalar ymean=r(mean)
estimates save "$path/`cov'_fpl_exp_`date'.ster", append

*Column 4: FPL > 1.38 & Expansion State
reg `cov'1718 treatment if notall16 == 1 & magi_fpl2015>1.38 & expansion == 1, cl(tin)
eststo
estadd scalar nobs e(N)
summ `e(depvar)' if e(sample)&treatment==0
estadd scalar ymean=r(mean)
estimates save "$path/`cov'_fpl_exp_`date'.ster", append

*Column 5: FPL <= 1.38 & Non-Expansion State
reg `cov'1718 treatment if notall16 == 1 & magi_fpl2015<=1.38 & expansion == 0, cl(tin)
eststo
estadd scalar nobs e(N)
summ `e(depvar)' if e(sample)&treatment==0
estadd scalar ymean=r(mean)
estimates save "$path/`cov'_fpl_exp_`date'.ster", append

*Column 6: FPL > 1.38 & Non-Expansion State
reg `cov'1718 treatment if notall16 == 1 & magi_fpl2015>1.38 & expansion == 0, cl(tin)
eststo
estadd scalar nobs e(N)
summ `e(depvar)' if e(sample)&treatment==0
estadd scalar ymean=r(mean)
estimates save "$path/`cov'_fpl_exp_`date'.ster", append

*Panel B: Ages 45-64

*Column 1: FPL <= 1.38
reg `cov'1718 treatment if notall16 == 1 & magi_fpl2015<=1.38 & age_45_64 == 1 , cl(tin)
eststo
estadd scalar nobs e(N)
summ `e(depvar)' if e(sample)&treatment==0
estadd scalar ymean=r(mean)
estimates save "$path/`cov'_fpl_exp_`date'.ster", append

*Column 2: FPL > 1.38
reg `cov'1718 treatment if notall16 == 1 & magi_fpl2015>1.38 & age_45_64 == 1, cl(tin)
eststo
estadd scalar nobs e(N)
summ `e(depvar)' if e(sample)&treatment==0
estadd scalar ymean=r(mean)
estimates save "$path/`cov'_fpl_exp_`date'.ster", append

*Column 3: FPL <= 1.38 & Expansion State
reg `cov'1718 treatment if notall16 == 1 & magi_fpl2015<=1.38 & expansion == 1 & age_45_64 == 1, cl(tin)
eststo
estadd scalar nobs e(N)
summ `e(depvar)' if e(sample)&treatment==0
estadd scalar ymean=r(mean)
estimates save "$path/`cov'_fpl_exp_`date'.ster", append

*Column 4: FPL > 1.38 & Expansion State
reg `cov'1718 treatment if notall16 == 1 & magi_fpl2015>1.38 & expansion == 1 & age_45_64 == 1, cl(tin)
eststo
estadd scalar nobs e(N)
summ `e(depvar)' if e(sample)&treatment==0
estadd scalar ymean=r(mean)
estimates save "$path/`cov'_fpl_exp_`date'.ster", append

*Column 5: FPL <= 1.38 & Non-Expansion State
reg `cov'1718 treatment if notall16 == 1 & magi_fpl2015<=1.38 & expansion == 0 & age_45_64 == 1, cl(tin)
eststo
estadd scalar nobs e(N)
summ `e(depvar)' if e(sample)&treatment==0
estadd scalar ymean=r(mean)
estimates save "$path/`cov'_fpl_exp_`date'.ster", append

*Column 6: FPL > 1.38 & Non-Expansion State
reg `cov'1718 treatment if notall16 == 1 & magi_fpl2015>1.38 & expansion == 0 & age_45_64 == 1, cl(tin)
eststo
estadd scalar nobs e(N)
summ `e(depvar)' if e(sample)&treatment==0
estadd scalar ymean=r(mean)
estimates save "$path/`cov'_fpl_exp_`date'.ster", append
}

log close

